package name.flurl.android.tt_news4android;

import name.flurl.android.tt_news4android.Tt_news4AndroidApplication.CONSTANTS;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;

class Tt_news4AndroidGestureDetector extends SimpleOnGestureListener {

	private Runnable mSwipeLeftRunnable = null;
	private Runnable mSwipeRightRunnable = null;
	private Runnable mSwipeUpRunnable = null;
	private Runnable mSwipeDownRunnable = null;

	public Tt_news4AndroidGestureDetector(Runnable leftRunnable,
			Runnable rightRunnable, Runnable upRunnable, Runnable downRunnable) {
		super();
		mSwipeLeftRunnable = leftRunnable;
		mSwipeRightRunnable = rightRunnable;
		mSwipeUpRunnable = upRunnable;
		mSwipeDownRunnable = downRunnable;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// Log.i("POGA Events", "-" + "FLING" + "-");
		if (e1.getX() - e2.getX() > CONSTANTS.SWIPE_MIN_DISTANCE
				&& Math.abs(velocityX) > CONSTANTS.SWIPE_THRESHOLD_VELOCITY) {
			if (mSwipeLeftRunnable != null)
				mSwipeLeftRunnable.run();
		} else if (e2.getX() - e1.getX() > CONSTANTS.SWIPE_MIN_DISTANCE
				&& Math.abs(velocityX) > CONSTANTS.SWIPE_THRESHOLD_VELOCITY) {
			if (mSwipeRightRunnable != null)
				mSwipeRightRunnable.run();
		}
		return false;
	}
}
